﻿
@section scripts{
    <script type="text/javascript">
        var P_province;
        var P_city;
        var P_district;

        var bootstrap = function ($, ibpm) {
            "use strict";
            var refreshCompanyData;
            var refreshGirdData;
            var page = {
                init: function () {
                    $("#En_add").on('click', page.AddAct);
                    $("#En_edit").on('click', page.EditAct);
                    $("#En_delete").on('click', page.DelAct);
                    $("#btn_Search").on('click', function () {
                        page.search();
                    });
                    $('#btn_Refresh').on('click', function () {
                        location.reload();
                    });
                    page.initGrid();
                    page.bind();
                },
                bind: function () {
                    //绑定时间组件
                    $('#F_FoundedTime').ibpm_datepicker(false);

                    //绑定下拉选项
                    $('#F_CompanyCategory').ibpm_select({
                        url: top.$.rootUrl + '/Org/Company/GetClassification',
                        value: 'Seq',
                        text: 'Val',
                        title: 'Key',
                        select: function (item) {
                            if (item != undefined && item != '' && item != null)
                                if (item.Seq != undefined && item.Seq != '' && item.Seq != null)
                                    $('#CompanyCategory').attr("value", item.Seq);
                        }
                    });

                    //配置上级公司
                    $('#F_ParentId').bind("click", function () {
                        ibpm.layerForm({
                            id: 'SelectCompany',
                            title: '选择上级机构',
                            url: top.$.rootUrl + '/Org/Company/GetSelectLayer',
                            width: 600,
                            height: 400,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshCompanyData);
                            }
                        });
                    });

                    //配置地区信息
                    $('#F_Province').bind("click", function () {
                        P_province = $('#Province').val();
                        P_city = $('#City').val();
                        P_district = $('#County').val();
                        ibpm.layerForm({
                            id: 'Distpicker',
                            title: '选择地区',
                            url: top.$.rootUrl + '/WorkDone/Distpicker',
                            width: 600,
                            height: 300,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshGirdData);
                            }
                        });
                    });
                },
                initGrid: function () {
                    $('#gridtable').jfGrid({
                        url: top.$.rootUrl + '/Org/Company/GetPageList',
                        headData: [
                            { label: '名称', name: 'FullName', index: "FullName", width: 200, align: 'left' },
                            { label: '编码', name: 'CompanyCode', index: "CompanyCode", width: 120, align: 'left' },
                            { label: '上级', name: 'ParentName', width: 120, align: 'center' },
                            { label: '负责人', name: 'Manager', width: 120, align: 'center' },
                            { label: "成立时间", name: "FoundedTimeWith", width: 120, align: "left" },
                            { label: '主页', name: 'WebAddress', width: 120, align: 'center' }
                        ],
                        mainId: 'CompanyId',
                        sidx: 'CompanyCode',    //排序
                        isPage: true,
                        rows: 12,
                    }).jfGridSet('reload'); //默认带数据
                },
                AddAct: function () {
                    ibpm.httpAsyncPost(top.$.rootUrl + "/Org/Company/NodeAdd", {}, function (json) {
                        $("#NodeSave").ibpm_SetFormData(json.data);
                        $('#AddNode').modal("show");
                        $('#F_CompanyCategory').ibpm_selectSet(json.data.CompanyCategory);
                    });
                },
                EditAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('CompanyId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.postForm(top.$.rootUrl + "/Org/Company/NodeEdit", { keyValue: keyValue }, function (json) {
                            $("#NodeSave").ibpm_SetFormData(json.data);
                            $('#AddNode').modal("show");
                            $('#F_CompanyCategory').ibpm_selectSet(json.data.CompanyCategory);
                            $('#ParentName').val(json.data.ParentName);
                            $('#FoundedTime').val(ibpm.formatDate(json.data.FoundedTime, "yyyy-MM-dd"));
                        });
                    }
                },
                DelAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('CompanyId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.layerConfirm('是否确认删除该项！', function (res) {
                            if (res) {
                                ibpm.deleteForm(top.$.rootUrl + '/Org/Company/NodeDelete', { keyValue: keyValue }, function () {
                                    page.search();
                                });
                            }
                        });
                    }
                },
                search: function (param) {
                    param = param || {};
                    param.keyword = $('#txt_Keyword').val();
                    $('#gridtable').jfGridSet('reload', param);
                }
            };
            page.init();
            refreshCompanyData = function (data) {
                if (data != null && !!data.CompanyId) {
                    var CompanyId = $('#CompanyId').val();
                    if (data.CompanyId != CompanyId) {
                        $('#ParentId').attr("value", data.CompanyId);
                        $('#ParentName').val(data.FullName);
                    }                    
                }
            };
            refreshGirdData = function (data) {
                if (data != null && !!data.province) {
                    $('#Province').val(data.province);
                    $('#City').val(data.city);
                    $('#County').val(data.district);
                }
            };
        };
        function EndReq(data) {
            $('#AddNode').modal("hide");
            $('#gridtable').jfGridSet('reload');
        };
    </script>
}

<div class="row">
    <div class="step-pane">
        <div class="row">
            <div class="col-md-5">
                <div class="input-group">
                    <input id="txt_Keyword" type="text" class="form-control-sm form-control" placeholder="请输入要查询的关键字" />
                    <span id="btn_Search" class="input-group-addon btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</span>
                    <span id="btn_Refresh" class="input-group-addon btn btn-info"><i class="fa fa-refresh"></i>&nbsp;刷新</span>
                </div>
            </div>
            <div class="col-md-7">
                <div class="btn-group btn-group-sm" style="float:right;">
                    <a id="En_add" class="btn btn-default"><i class="fa fa-plus"></i>&nbsp;新增机构</a>
                    <a id="En_edit" class="btn btn-default"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑机构</a>
                    <a id="En_delete" class="btn btn-default"><i class="fa fa-trash-o"></i>&nbsp;删除机构</a>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="step-pane">
        <div id="gridtable" style="margin-top:10px;"></div>
    </div>
</div>

<div class="modal fade" id="AddNode" tabindex="-11" role="dialog" aria-labelledby="AddNode" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h3 class="modal-title">机构基础信息</h3>
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
            </div>
            <form action="/Org/Company/NodeSave" id="NodeSave" method="post" onsubmit="return FormSaveReport('NodeSave');">
                <div class="modal-body">
                    <input type="hidden" id="CompanyId" name="CompanyId" value="" />
                    <input type="hidden" id="ParentId" name="ParentId" value="" />
                    <input type="hidden" id="CompanyCategory" name="CompanyCategory" value="" />
                    <input type="hidden" id="ModifyUserId" name="ModifyUserId" value="" />
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>机构编码</label>
                            <input class="form-control single-line" id="CompanyCode" name="CompanyCode" type="text" readonly>
                        </div>
                        <div class="form-group col-sm-6">
                            <label>成立时间</label>
                            <div class="input-group date" id="F_FoundedTime">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" class="form-control" placeholder="成立时间" id="FoundedTime" name="FoundedTime" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>机构分类</label>
                            <div class="block">
                                <div id="F_CompanyCategory"></div>
                            </div>
                        </div>
                        <div class="form-group col-sm-6">
                            <label>上级机构</label>
                            <div class="input-group date" id="F_ParentId">
                                <span class="input-group-addon"><i class="fa fa-cube"></i></span>
                                <input class="form-control" id="ParentName" name="ParentName" readonly type="text" value="">
                            </div>
                        </div>
                    </div>
                    <div class="block">
                        <div class="form-group">
                            <label>机构名称</label>
                            <input class="form-control single-line" id="FullName" name="FullName" placeholder="机构名称" type="text" value="">
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label>所在省</label>
                            <div class="input-group date" id="F_Province">
                                <span class="input-group-addon"><i class="fa fa-address-card"></i></span>
                                <input class="form-control" id="Province" name="Province" readonly type="text" value="">
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label>所在市</label>
                            <input class="form-control" id="City" name="City" readonly type="text" value="">
                        </div>
                        <div class="form-group col-sm-4">
                            <label>所在县/区</label>
                            <input class="form-control" id="County" name="County" readonly type="text" value="">
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <label>负责人</label>
                            <input class="form-control single-line" id="Manager" name="Manager" placeholder="负责人" type="text" value="">
                        </div>
                        <div class="form-group col-sm-8">
                            <label>主页</label>
                            <input class="form-control single-line" id="WebAddress" name="WebAddress" placeholder="主页" type="text" value="">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
                    <input type="submit" value="Save" class="btn btn-success">
                </div>
            </form>
        </div>
    </div>
</div>
